﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;
using System.Web.Routing;

namespace ScoutNET.Helpers
{
    public static class ExtrenalLinkHelper
    {
        public static MvcHtmlString ExtrenalLink(this HtmlHelper htmlHelper, string url, string value)
        {
            return ExtrenalLink(htmlHelper, url, value, null);
        }

        public static MvcHtmlString ExtrenalLink(this HtmlHelper htmlHelper, string url, string value, object htmlAttributes)
        {
            if (String.IsNullOrEmpty(url))
            {
                throw new ArgumentException("The argument must have a value", "url");
            }

            if (String.IsNullOrEmpty(value))
            {
                throw new ArgumentException("The argument must have a value", "value");
            }

            TagBuilder builder = new TagBuilder("a");
            builder.MergeAttributes<string, object>((IDictionary<string, object>)new RouteValueDictionary(htmlAttributes));
            builder.MergeAttribute("href", url);
            builder.SetInnerText(value);

            return MvcHtmlString.Create(builder.ToString(TagRenderMode.Normal));
        }
    }
}
